package day12;

import java.io.*;

/**
 * @author Xiao
 * @date 2021/8/3
 */
public class BytsStreamDemo02 {
    /**
     * 使用字节缓冲流拷贝文件“JavaSE_Advance\classpractice\src\day12\demo02.txt”
     * 到“JavaSE_Advance\classpractice\src\day12\demo02Copy.txt”
     */
    public static void main(String[] args) throws IOException {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
                "classpractice\\src\\day12\\demo02.txt"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(
                "classpractice\\src\\day12\\demo02Copy.txt"));
//        readBytes(bis, bos);
        readByte(bis, bos);
        bis.close();
        bos.close();
    }

    private static void readByte(BufferedInputStream bis, BufferedOutputStream bos) throws IOException {
        int read;
        while ((read = bis.read()) != -1) {
            bos.write(read);
        }
    }

    private static void readBytes(BufferedInputStream bis, BufferedOutputStream bos) throws IOException {
        byte[] bytes = new byte[1024];
        int len;
        while ((len = bis.read(bytes)) != -1) {
            bos.write(bytes,0,len);
        }
    }
}
